<template>
  <div id="loginPage">
    <div id="nav">
      <div id="logo">
        <img src="/static/images/logo.png">
      </div>
      <a class="support" href="/html/suport.html" target="_blank">使用支持</a>
    </div>
    <div id="container">
      <div class="left">
        <img src="/static/images/media.png">
      </div>
      <div class="loginBody">
        <div class="login-right" v-show="isForget">
          <form @submit="submit" class="middle" autocomplete="off">
            <div class="login-main-form">
              <div class="fs-28 login-title">欢迎登录直播云平台</div>
              <div class="error-msg" v-show="errorMsg!=''">{{errorMsg}}</div>
              <div class="padding-top-10">
                <el-input
                  v-model="formdata.account"
                  placeholder="请输入登录邮箱"
                  name="userName"
                  @focus="clearErr"
                  auto-complete="on"
                ></el-input>
              </div>
              <div class="padding-top-20">
                <el-input
                  type="password"
                  v-model="formdata.passwd"
                  placeholder="请输入登录密码"
                  @focus="clearErr"
                  auto-complete="false"
                ></el-input>
              </div>
              <div class="login-lastline">
                <el-checkbox v-model="checked">记住账号</el-checkbox>
                <span class="forgetPwd cursor" @click="isForget = false">忘记密码？</span>
              </div>
              <input type="submit" style="display:none">
              <el-button
                class="login-button"
                type="primary"
                size="large"
                :loading="loading"
                @click="login"
              >登&nbsp;&nbsp;录</el-button>
            </div>
          </form>
        </div>
        <div class="login-right" v-show="!isForget">
          <form @submit="submit" class="middle" autocomplete="off">
            <div class="login-main-form">
              <div class="fs-28 login-title">忘记密码？</div>
              <div class="padding-top-10">
                <el-input v-model="email" placeholder="请输入收件邮箱"></el-input>
              </div>
              <div class="btnContain">
                <el-button type="text" class="backBtn" @click="isForget = true">返回登陆页面</el-button>
              </div>
              <el-button class="login-button" type="primary" size="large" @click="confirm">提交</el-button>
            </div>
          </form>
        </div>
      </div>
    </div>
    <div class="bottom">
      <img src="/static/images/socket.png" alt>
    </div>
  </div>
</template>
<script>
import "@SCSS/common.scss";
import userModel from "@M/user";
import commonModel from "@M/common";
export default {
  data() {
    return {
      email: "",
      isForget: true,
      formdata: {
        account: "",
        passwd: ""
      },
      checked: false,
      loading: false,
      errorMsg: "",
      showTopTip: false
    };
  },
  methods: {
    confirm() {
      if(!this.email){
        this.$message.warning("请输入邮箱");
        return;
      }else if (!this.$utils.isEmail(this.email)) {
        this.$message.warning("请填写正确邮箱格式");
        return;
      }
      this.$postStream("/admin/auth/auhtUser/sandResetMail.do", {
        data: {
          email: this.email
        },
        success: res => {
          if (res.success) {
            this.$message.success("邮件发送成功");
          } else {
            this.$message.error("邮件发送失败");
          }
        },
        error: () => {
          this.$message.error("邮件发送失败");
        }
      });
    },
    showTipMethod() {
      this.showTopTip = 0;
      localStorage.setItem("showTopTip", 0);
    },
    submit(evt) {
      evt.preventDefault();
      this.login();
    },
    login() {
      this.clearErr();
      let self = this;
      this.loading = true;

      if (!this.formdata.account || !this.formdata.passwd) {
        this.errorMsg = "请输入账号或密码";
        this.loading = false;
      } else {
        userModel.userLogin(
          this.formdata,
          this.checked,
          () => {
            self.loading = false; //登录时的回调
          },
          (mes, type) => {
            self.errorMsg = mes; //登录失败时的回调
          },
          data => {
            if (!data.toggle) {
              // window.location.href = "index.html";
              this.$postStream(
                "/admin/instance/ccb/polyv/authUser/userInfo/get.do",
                {
                  data: {},
                  success: res => {
                    if (res.success) {
                      sessionStorage.setItem(
                        "curAccountAppId",
                        res.object.appId
                      );
                      sessionStorage.setItem(
                        "curAccountEmail",
                        res.object.email
                      );
                      sessionStorage.setItem("userType", res.object.userType);
                      //userType:1为应用管理员，2为频道管理员，3为平台管理员 4为超级管理员
                      if (res.object.userType == "4") {
                        if (!data.toggle) {
                          window.location.href = "index.html#/auth-app/list";
                        } else {
                          window.location.href = "toggle.html";
                        }
                      } else if (res.object.userType == "3") {
                        window.location.href = "index.html#/appList";
                      } else if (res.object.userType == "2") {
                        window.location.href = "index.html#/channelManage";
                      } else {
                        window.location.href = "index.html#/detail";
                      }
                    } else {
                      self.errorMsg = "获取账号信息失败";
                    }
                  },
                  complete: () => {
                    self.loading = false; //登录时的回调
                  },
                  error: () => {
                    self.errorMsg = "获取账号信息失败";
                  }
                }
              );
            } else {
              window.location.href = "toggle.html";
            }
          }
        );
      }
    },
    clearErr() {
      this.errorMsg = "";
    }
  },
  mounted() {
    this.showTopTip = localStorage.getItem("showTopTip") || 1;
    let account = localStorage.getItem("account");
    let passwd = localStorage.getItem("passwd");
    if (account) {
      this.checked = true;
      this.formdata.account = account;
      this.formdata.passwd = passwd;
    }
  }
};
</script>

<style style lang="scss">
@import "../../assets/scss/variable.scss";
@mixin sprites() {
  background: url("../../assets/images/sprites1.png");
  background-size: 1000px 1200px;
}
.btnContain {
  position: relative;
  height: 30px;
}
.submitEm {
  width: 40%;
  margin: 0 auto;
  padding-top: 20%;
  text-align: center;
  p {
    font-size: 3rem;
  }
  input {
    margin: 2rem 0;
  }
}
.fs-28 {
  font-size: 28px;
}
.padding-top-10 {
  padding-top: 10px;
}
.padding-top-20 {
  padding-top: 20px;
}
.logo-icon {
  display: block;
  @include sprites();
}
.btn-size {
  width: 130px;
  height: 40px;
}
#app {
  height: 100%;
  display: flex;
  overflow: hidden;
  min-height: 580px;
}
.div-center {
  margin: 0 auto;
}
.bottom {
  padding-bottom: 30px;
  text-align: center;
  width: 100%;
}
.login-left {
  position: relative;
  width: 500px;
  background: url("../../assets/images/login.png");
  background-size: 500px auto;
  .logo-icon {
    position: absolute;
    top: 37px;
    left: 34px;
    width: 50px;
    height: 50px;
    background-position: 0 540px;
  }
  .logo-text-icon {
    @include sprites();
    background-position: -118px 620px;
    display: inline-block;
    width: 104px;
    height: 28px;
    position: relative;
    top: 6px;
  }
  .content {
    color: #fff;
    margin-top: 173px;
  }
  .btn-more {
    color: $xy-color-main;
    border: 1px solid $xy-color-main;
    background-color: rgba(0, 0, 0, 0);
    transition: background 300ms;
    &:hover {
      background-color: $xy-color-main;
      color: #fff;
    }
  }
  p {
    &:nth-child(1) {
      font-size: 18px;
      line-height: 1;
      font-weight: 300;
    }
    &:nth-child(2) {
      font-size: 28px;
      line-height: 40px;
      height: 40px;
      margin-bottom: 80px;
      font-weight: 300;
      position: relative;
    }
    &:nth-child(3) {
      font-size: 18px;
      line-height: 30px;
      margin-bottom: 30px;
      width: 400px;
      font-weight: 300;
      width: 400px;
    }
  }
  .bottom {
    position: absolute;
    bottom: 0;
    font-weight: 300;
    font-size: 12px;
    width: 500px;
    color: #fff;
  }
}
.login-right {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  .top {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 37px 30px;
    .top-span {
      color: $xy-text-color-regular;
    }
    .btn-register {
      color: $xy-text-color-regular;
      border: 1px solid $xy-border-color-light;
      border-radius: 3px;
      background-color: rgba(0, 0, 0, 0);
      transition: background, color 300ms;
      &:hover {
        color: #ffffff;
        border: 1px solid $xy-color-main;
        background-color: $xy-color-main;
      }
    }
  }
  .backBtn {
    position: absolute;
    right: 0px;
  }
  .logo-icon {
    width: 380px;
    height: 50px;
    background-position: 0 540px;
  }
  .middle {
    width: 100%;
    position: relative;
    display: flex;
    min-width: 320px;
    background: #fff;
    border-radius: 10px;
    .login-title {
      color: #0249b0;
      font-size: 20px;
      font-weight: bold;
      font-family: "Microsoft Yahei";
      text-align: center;
    }
    .login-title::after {
      content: "";
      display: block;
      background: #0249b0;
      height: 3px;
      width: 100px;
      margin: 20px auto;
    }
    .error-msg {
      font-size: 12px;
      color: #fa5555;
      line-height: 14px;
    }
    .forget-pwd {
      color: $xy-color-main;
      cursor: pointer;
    }
    .login-main-form {
      margin: 0 auto;
      width: 423px;
      padding: 30px 20px;
      position: relative;
      .login-lastline {
        position: relative;
        height: 20px;
        line-height: 20px;
        margin: 20px auto 30px;
      }
      .login-button {
        width: 100%;
        margin: 0px;
      }
    }
  }
  .bottom {
    .login-copyright {
      margin-top: 8px;
      font-size: 12px;
      color: $xy-text-color-secondary;
      a {
        color: $xy-text-color-secondary;
        text-decoration: none;
      }
    }
  }
}
@media screen and (max-width: 1025px) {
  .login-left {
    display: none;
  }
  .login-right {
    width: 100%;
  }
}
@media screen and (min-width: 1025px) {
  .login-right {
    .logo-icon {
      display: none;
    }
    .top {
      justify-content: flex-end;
    }
  }
}
@media screen and (max-width: 660px) {
  .login-right {
    .logo-icon {
      width: 50px;
      background-position: 0 540px;
    }
  }
}
@media screen and (max-width: 406px) {
  .login-main-form {
    width: 100%;
  }
  .login-right {
    .top {
      padding: 20px;
    }
  }
}
@media screen and (max-width: 420px) {
  .el-message-box {
    width: 100%;
  }
}
.el-checkbox {
  color: $xy-text-color-primary;
}
.el-button,
.el-checkbox {
  font-weight: 400;
}
.el-checkbox__input.is-checked {
  & + .el-checkbox__label {
    color: $xy-text-color-primary;
  }
}
.login-top {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 14px;
  line-height: 30px;
  background: #ffd39b;
  opacity: 0.8;
  z-index: 2000;
  .icon-hint-warning1 {
    color: $xy-color-danger;
  }
  .download {
    border: none;
    outline: none;
    border-radius: 3px;
    background: transparent;
    height: 24px;
    line-height: 24px;
    margin-left: 10px;
    padding: 1px 6px;
    background-color: $xy-color-main;
    color: #fff;
    &:hover {
      background-color: #0d84ff;
      border-color: #0d84ff;
    }
  }
}
.forgetPwd {
  color: #4099fe;
  position: absolute;
  right: 0;
}
#nav {
  height: 70px;
  background: #00ccff;
  align-items: center;
  display: flex;
}
#logo {
  width: 342px;
  height: 40px;
  margin-left: 13%;
}
#container {
  padding:0 80px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.left {
  width: 572px;
  height: 357px;
}
.loginBody {
  width: 340px;
  box-shadow: 5px 5px 5px #00ccff;
  padding: 0px;
}
#loginPage {
  background: #4DDAF2;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  justify-content: space-between;
  min-width: 1200px;
}
.bottom {
  padding: 0px;
  img {
    float: right;
    margin-right: 10%;
  }
}
.support{
  color:#fff;
  position:absolute;
  right:13%;
}
</style>
